<?php
if (!defined('IN_DISCUZ')){
	exit('Access Denied');
}

global $_G, $sid;
$param = false;
$mySql = '';
$moreJS = 1;

$attr = isset($_G['gp_attr']) ? strval($_G['gp_attr']) : '';
$view = isset($_G['gp_view']) ? strval($_G['gp_view']) : '';
$page = isset($_G['gp_page']) ? intval($_G['gp_page']) : 0;
$sort = isset($_G['gp_sort']) ? strval($_G['gp_sort']) : 'last';

/*************LOAD MENU CATGORIES***************/
$shop_menu = shop_menu($sid);

if (!empty($shop_menu)){
	$isMenu = 1;

	switch ($view){
		case 'list':
			$view = 'list';
		break;
		default:
			$view = 'grid';
		break;
	}
}else{
	$isMenu = 0;

	switch ($view){
		case 'grid':
			$view = 'grid';
		break;
		default:
			$view = 'list';
		break;
	}

	if (empty($_G['shop']['param']))
		$param = false;
	else{
		$param = true;

		// Load param of this category
		$allParam = listAttr($sid);
		$totalParam = count($allParam);

//		$mySql .= searchAttr(attrArray($attr), $attr);
	}
}

//////////////////////////////////////////////////////////////////////////////////////

$limit = $item_per_page;
$curpage = is_numeric($_G['gp_page']) ? intval($_G['gp_page']) : 1;
$start = ($curpage - 1) * $limit;
$count = 0;

$_G['gp_ajaxtarget'] = 'listproduct_display';

$xUrl = '';
$vUrl = '';
$sUrl = 'shop.php?name=' . locdau($_G[shop][name]) . '&amp;sid=' . $sid;

if ($sort)
	$xUrl = '&amp;sort=' . $sort;
if ($page)
	$xUrl = '&amp;page=' . $page;
if ($view){
	$xUrl = '&amp;view=' . $view;
	$vUrl = $sUrl . $xUrl;
}

$url = $sUrl . $xUrl;

$result = productList($sid, $mySql, $sort, $start, $limit, $count, true, true);
$pages = multi($count, $limit, $curpage, $url, 0, 10, false, false, 0);
//var_dump($result);
$have = count($result);

unset($_G['gp_ajaxtarget']);

/*********************SEO category***********************/
$navtitle = '';
$navtitle .= $_G['shop']['name'];

switch ($sort){
	case 'pasc':
		$navtitle .= lang('shop/template', 'title_gia_thap_nhat');
	break;
	case 'pdesc':
		$navtitle .= lang('shop/template', 'title_gia_cao_nhat');
	break;
	case 'sale':
		$navtitle .= lang('shop/template', 'title_hang_giam_gia');
	break;
}

$metakeywords = $_G['shop']['keywords'] ? $_G['shop']['keywords'] : $_G['shop']['name'];
$metadescription = $_G['shop']['seodescription'] ? $_G['shop']['seodescription'] : $_G['shop']['description'];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

include template('shop/category');

unset($shop_menu);